package org.jeecg.modules.param.member.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.param.member.service.IBikeMemberUserCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: IC卡接口
 * @Author: 月月鸟
 * @Date:   2021-05-25
 * @Version: V1.0
 */
@Api(tags="IC卡接口")
@RestController
@RequestMapping("/member/userCar")
@Slf4j
public class BikeMemberUserCardController {

    @Autowired
    private IBikeMemberUserCardService bikeMemberUserCardService;

    @ApiOperation(value="数据管理-初始化IC卡", notes="数据管理-初始化IC卡")
    @DeleteMapping("/initialize")
    public Result<?> initialize (@RequestParam(required = false) String icCode){
        //判断是否有人使用，无人使用初始化卡片并入库
        return bikeMemberUserCardService.initialize(icCode);
    }

    @ApiOperation(value="初始化卡密钥-存入卡信息", notes="初始化卡密钥-存入卡信息")
    @DeleteMapping("/initializeKey")
    public Result<?> initializeKey (@RequestParam(required = false) String icCode){
        //1.判断卡片是否入库；2.入库则判断是否无人使用此卡；
        return bikeMemberUserCardService.initializeKey(icCode);
    }
    @ApiOperation(value="生成IC卡号", notes="生成IC卡号")
    @GetMapping("/creatIcCardCode")
    public Result<?> creatIcCardCode (){
        return bikeMemberUserCardService.creatIcCardCode();
    }


    @AutoLog(value = "管理卡操作-发卡",operateType = 2)
    @ApiOperation(value="发管理卡", notes="发管理卡")
    @PutMapping("/adminCard")
    public Result<?> adminCard(@RequestParam(value = "id",required = false) String id,@RequestParam(value = "icCode",required = false) String icCode,
                               @RequestParam(value = "cardType",required = false) String cardType,@RequestParam(value = "cardNumber",required = false)String cardNumber ){
        return bikeMemberUserCardService.adminCard(id,icCode,cardType,cardNumber);
    }
    @AutoLog(value = "管理卡操作-挂失-解挂失-退卡",operateType = 3)
    @ApiOperation(value="管理卡状态 1 挂失 2 解挂失 3 退卡", notes="管理卡状态1 挂失 2 解挂失 3 退卡")
    @PutMapping("/putCard")
    public Result<?> putCard(@RequestParam(value = "id",required = false) String id,@RequestParam(value = "type",required = false) String type){
        return bikeMemberUserCardService.putCard(id,type);
    }
    @ApiOperation(value="写IC卡密钥", notes="写IC卡密钥")
    @GetMapping("/getKeys")
    public Result<?> getKeys(){
        return bikeMemberUserCardService.getKeys();
    }
    @ApiOperation(value="写IC卡密钥", notes="写IC卡密钥")
    @GetMapping("/verifyKeys")
    public Result<?> verifyKeys(@RequestParam(required = true) String keys){
        return bikeMemberUserCardService.verifyKeys(keys);
    }
}
